package web.PetStore.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

public class Order implements Serializable {

    private static final long serialVersionUID = 8329559983943337176L;
    private static final String ORDER_SRC_PREFIX = "<a href=\"/Order?orderId=";
    private static final String ORDER_SRC_POSTFIX = "\">查看订单</a>";
    private final String SRC_PREFIX = "<a class=\"orderLink\" href=\"/ProductForm?productId=";
    private String SRC_POSTFIX = "class=\"small_img\"/></a>";
    private String curType = "small";
    private String orderid;
    private BigDecimal unitprice;
    private BigDecimal price;
    private int num;
    private Timestamp time;
    private String userid;
    private String productid;
    private String name;
    private String orderSrc;
    private String imageSrc;
    private String phone;
    private String address;
    private boolean srcFix;

    public String getOrderid() {
        return orderid;
    }

    public void setOrderid(String orderid) {
        this.orderid = orderid;
        this.orderSrc = ORDER_SRC_PREFIX + orderid + ORDER_SRC_POSTFIX;
    }

    public BigDecimal getUnitprice() {
        return unitprice;
    }

    public void setUnitprice(BigDecimal unitprice) {
        this.unitprice = unitprice;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getProductid() {
        return productid;
    }

    public void setProductid(String productid) {
        this.productid = productid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    public String getOrderSrc() {
        return orderSrc;
    }

    public String getImageSrc() {
        if(srcFix){
            return imageSrc;
        }
        return SRC_PREFIX + productid + imageSrc + SRC_POSTFIX;
    }

    public void setImageSrc(String imageSrc) {
        this.imageSrc = imageSrc;
        srcFix = imageSrc.startsWith("href", 3);
        if(srcFix){
            this.imageSrc = imageSrc.replace("big", curType);
        }
    }

    public void setImageSize(String type){
        if(srcFix){
            imageSrc = imageSrc.replace(curType, type);
            curType = type;
            return;
        }
        SRC_POSTFIX = SRC_POSTFIX.replace(curType, type);
        curType = type;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
